package me.yricky.mayu.ui.tasks

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.items
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import me.yricky.mayu.ui.LazyColumnWithScrollBar
import me.yricky.mayu.ui.ItemCard
import me.yricky.mayu.ui.tasks.taskui.orf.ORFFindTaskEntry
import me.yricky.mayu.ui.tasks.taskui.seqali.SeqAlignmentTaskEntry

/**
 * @author Yricky
 * @date 2022/4/20
 */

@Composable
fun TasksListModel.Page(modifier: Modifier = Modifier){
    Column(modifier) {
        var atTemplate by remember { mutableStateOf(list.isEmpty()) }
        TabRow(
            selectedTabIndex = if(atTemplate) 1 else 0,
            modifier = Modifier.fillMaxWidth(),
            backgroundColor = MaterialTheme.colors.background,
            contentColor = MaterialTheme.colors.primary
        ) {
            Tab(
                selected = !atTemplate,
                onClick = { atTemplate = false },
                modifier = Modifier.weight(1f),
                text = { Text("任务列表") },
            )
            Tab(
                selected = atTemplate,
                onClick = { atTemplate = true },
                modifier = Modifier.weight(1f),
                text = { Text("新建任务") },
            )
        }
        if(atTemplate){
            TaskTemplate()
        }else{
            LazyColumnWithScrollBar(Modifier.fillMaxSize()){
                items(list){
                    ItemCard(Modifier.padding(8.dp,4.dp)){
                        it.ContentItem(Modifier.fillMaxWidth().padding(8.dp))
                    }
                }
            }
        }
    }
}

@Composable
fun TaskTemplate(){
    LazyVerticalGrid(GridCells.Adaptive(160.dp),Modifier.fillMaxWidth()) {
        item { SeqAlignmentTaskEntry() }
        item { ORFFindTaskEntry() }
    }
}